package br.com.lolprojects.lolcalc.util;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class ResponseUtil {

	public static Response responseHTML(String html) {
		return Response.status(200).entity(html.toString())
				.type(MediaType.TEXT_HTML).build();
	}

	public static Response responseJSON(Object obj) {
		ObjectMapper mapper = new ObjectMapper();
		String json = new String();
		try {
			json = mapper.writeValueAsString(obj);
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return Response.status(200).entity(json)
				.type(MediaType.APPLICATION_JSON).build();
	}

}
